package com.wang.study.mapper;

import com.wang.study.commons.CommonsUtils;
import com.wang.study.model.Cart;
import com.wang.study.model.CartAndUidAndCategory;
import com.wang.study.model.Order;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

public interface CartMapper {
    @Insert("insert into mall_cart(userid,goodid,nums,total) values(#{userid},#{goodid},#{nums},#{total})")
    Integer insertCart(Cart cart);
    @Select("select * from mall_cart where userid=#{userid} and goodid=#{goodid}")
    Cart findCartByUidAndGid(@Param("userid") Integer userid, @Param("goodid") Integer goodid);
    @Update("update mall_cart set nums=#{nums},total=#{total} where userid=#{userid} and goodid=#{goodid}")
    Integer updateCart(Cart cartDB);
    @Select("select * from mall_cart where userid=#{userid}")
    List<Cart> selectCartByUid(Integer uid);
    @Select("SELECT c.id,g.name,g.image,c.nums,c.total from mall_cart c join mall_goods g on g.id=c.goodid where  g.id=#{goodid}")
    CartAndUidAndCategory selectCart(Integer goodid);
    @Delete("delete from mall_cart where id = #{ids}")
    Integer delCartById(Integer ids);
    @DeleteProvider(type = CommonsUtils.class,method = "getDelUserSql")
    Integer delCartById2(@Param("ids") ArrayList<Integer> ids);
    @Update("update mall_cart set nums=#{nums},total=#{total} where id=#{id}")
    Integer upDateById(@Param("id") Integer id,@Param("nums")Integer nums,@Param("total")Integer total);
    @Select("select * from mall_order where userid=#{uid}")
    List<Order> showOrderByUserId(String uid);
}